<?php
/**
 * @purpose: 对“通知”类型中子类型为5(生日提醒)的编码与解码文件
 * @author: Mandel Woo <wuzhijian@snda.com>

 * @memo: 参阅母板文件
 */
require_once(dirname(__FILE__)."/../../../models/user/UCModUserInfo.php");


function msg_notice_type5_encoder() {
	$fields = array("birthday_sdid");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	return serialize(array(
			"birthday_sdid" => $birthday_sdid,
			));
}

function msg_notice_type5_decoder() {
	$fields = array("id","receiverid","content","createTime","changeFlag","fmt");

	foreach($fields as $k => $v) {
		eval("\${$v}=func_get_arg($k);");
	}

	$data = unserialize($content);
	$birthday_sdid = $data['birthday_sdid'];

	$user_info = UCModUserInfo::getUserInfo($birthday_sdid, array(USERINFO_NICKNAME, USERINFO_GENDER));
	$nickname  = $user_info[USERINFO_NICKNAME];
	$nickname  == '' && $nickname = $birthday_sdid; #取不到昵称
	$nickname  = htmlspecialchars($nickname);

	$user        = "<a href=\"".get_user_home_url($birthday_sdid)."\" target='_blank'>{$nickname}</a>";
	$gender_desc = $user_info[USERINFO_GENDER] == 1 ? '他' : '她';

	#!!!输出处将不做html转义，须保证用户输入数据的安全
	if ($fmt == 'line') {
		return sprintf("今天是您的好友%s的生日，赶快给%s留言送去生日的祝福吧！", $user, $gender_desc);

	} else if ($fmt == 'box') {
		$html = sprintf("今天是您的好友%s的生日，赶快给%s<a href=\"/home/message/home/%d\" target=\"_blank\">留言</a>送去生日的祝福吧！", $user, $gender_desc, $birthday_sdid);

		return '<div class="font14">' . $html . '</div>';

	} else {
		return '';
	}
}



